package com.store.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Data
public class User {
    private Long id;                    // 用户ID
    private String username;            // 用户名
    private String password;            // 密码
    private String role;                // 角色：ADMIN-管理员，SUPER_ADMIN-超级管理员，USER-普通用户
    private LocalDateTime lastLoginTime; // 最后登录时间
    private LocalDateTime createTime;    // 创建时间
    private LocalDateTime updateTime;    // 更新时间

    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorities = new ArrayList<>();
        if (role != null) {
            authorities.add(new SimpleGrantedAuthority("ROLE_" + role));
        }
        return authorities;
    }
} 